package com.iot.iotplus.controller;

import com.iot.iotplus.base.CommonPage;
import com.iot.iotplus.base.Result;
import com.iot.iotplus.entity.Product;
import com.iot.iotplus.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/list/{pageNumber}/{pageSize}")
    public Result<?> list(@PathVariable("pageNumber") Integer pageNumber, @PathVariable("pageSize") Integer pageSize) {
        return productService.productList(pageNumber, pageSize);
    }

    @GetMapping("/get/{productID}")
    public Result<?> get(@PathVariable("productID") Long productID) {
        return productService.getProduct(productID);
    }

    @DeleteMapping("/delete/{productID}")
    public Result<?> delete(@PathVariable("productID") Long productID) {
        return productService.deleteProduct(productID);
    }
    @PostMapping("/add")
    public Result<?> add(@RequestBody Product product) {
        return productService.addProduct(product);
    }
    @GetMapping("/byts/{tenantId}")
    public Result<?> bytIDGetProducts(@PathVariable("tenantId") String tenantId) {
        return productService.bytIDGetProducts(tenantId);
    }

}
